/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
#pragma once

#include "DBSession.h"
#include <sqlext.h>
#include <sqltypes.h>
#include "ODBC_DBError.h"

/**
* @class ODBC_DBSession
*  - 
*/ 
class ODBC_DBStatement;
class ODBC_DBSession : public DBSession{
	enum{
		DEF_CONNECTION_STRING_SIZE=		1024,
		DEF_CONN_STR_LEN=				2048,
		DEF_ERR_MSG_LEN=				1024,
	};

public:
	void reset(){};

	virtual void set_error( void* data, char* sql, char* method, int line );
	virtual DBError* get_error();

	virtual int connect();
	virtual int reconnect();
	virtual int isActive();
	virtual int disconnect();
	virtual bool setTimeout( size_t timeout );

	SQLHDBC	getSession(){ return hdbc_; }
	DBStatement* get_statement();
	
	virtual int get_table_desc( void* handle, char* table_name, DBTableDescription& desc );

	static int odbc_install( const char* dsn, const char* ip, \
		const char* db, const char* desc, const char* driver_name );
	static int odbc_uninstall( const char* dsn, const char* driver );	

	ODBC_DBSession( DBAccount& account );
	virtual ~ODBC_DBSession();

protected:

private:	
	bool availableTransaction();
	bool check_account();

	SQLHENV env_;
	SQLHDBC	hdbc_;
	bool available_transaction_;

	ODBC_DBStatement* stmt_;
	ODBC_DBError error_;
};
